package com.samsung.app;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class WifiDialog extends Dialog
{
  public static final String TAG = "INRY";
  AccessPointAdapter accessPointAdapter;
  Button btnClose;
  Button btnRefresh;
  Comparator<ScanResult> compare = new Comparator<ScanResult>()
  {
    public int compare(ScanResult paramScanResult1, ScanResult paramScanResult2)
    {
      int i = paramScanResult1.level;
      int j = paramScanResult2.level;
      int k = 1;
      if (i > j){
        k = -1;
      }
      else if (i != j){
        k = 0;
      	}
      return k;
      }
  };
  boolean isConnected = false;
  ListView listView;
  AlertDialog.Builder mAdialog = null;
  Button mConnectBtn;
  private Context mContext = null;
  ExToast mExToast = ExToast.getInstance();
  WifiManager mWifiManager;
  ProgressBar progressBar;
  List<ScanResult> scanResult;
  List<WifiConfiguration> wifiConfigurationList;
  WifiStateChangedReceiver wifiStateChangedReceiver = new WifiStateChangedReceiver();

  public WifiDialog(Context paramContext)
  {
    super(paramContext, 2131034113);
    this.mContext = paramContext;
  }

  private boolean WPSChecker(String paramString)
  {
    Logger.d("INRY", "ap.length() is " + paramString.length());
    if (paramString.length() == 5)
    {
      if ((!paramString.equals("[WPS]")) && (!paramString.equals("[ESS]")))
        return false;
    }
    	else if ((paramString.length() == 10) && (paramString.equals("[WPS][ESS]")))
      {
    	return true;
      }
    return false;
  }

  private void accessPointScan()
  {
    Logger.d("INRY", "accessPointScan");
    ArrayList<ScanResult> wifilist = new ArrayList<ScanResult>();
    List<ScanResult> wifiManagerScanResults = null;
    if (this.mWifiManager.startScan())
    {
      this.wifiConfigurationList = this.mWifiManager.getConfiguredNetworks();
      this.progressBar.setVisibility(0);
      this.scanResult.clear();
      wifiManagerScanResults = this.mWifiManager.getScanResults();
      if (wifiManagerScanResults != null)
      {
    	  boolean add = true;
      		for(ScanResult localScanResult: wifiManagerScanResults){
      			add = true;
      			for(ScanResult globalScanResutl: this.scanResult){
      				if(localScanResult.SSID.equals(globalScanResutl.SSID)){
      					add = false;
      					break;
      				}
      			}
      			if(add){
      				wifilist.add(localScanResult);
      			}
      		}
     
        	for(ScanResult localScanResult3 : wifilist){
	          if (Utils.supportDSCPrefix(localScanResult3.SSID))
	        	  this.scanResult.add(localScanResult3);
	          }
      }
      else
      {
        if (this.scanResult.size() != 0){
        	((TextView)findViewById(2131099688)).setVisibility(8);
        	Collections.sort(this.scanResult, this.compare);
        	this.mExToast.show(String.valueOf(3));
        }
        ((TextView)findViewById(2131099688)).setText(2130968618);
        ((TextView)findViewById(2131099688)).setVisibility(0);
      }
    }
  }

  private void connect(WifiConfiguration paramWifiConfiguration)
  {
    this.progressBar.setVisibility(0);
    int i = this.mWifiManager.addNetwork(paramWifiConfiguration);
    if (this.mWifiManager.enableNetwork(i, true)){
      Logger.d("INRY", "Connected!");
    }
    else{
      Logger.d("INRY", "Disconnected!");
    }
  }

  private String disconnectTheOtherWifi()
  {
    String str = this.mWifiManager.getConnectionInfo().getSSID();
    if ((str != null) && (!Utils.supportDSCPrefix(str)))
    {
      this.mWifiManager.disconnect();
      return str;
    }
    return "";
  }

  private int getSignalResId(int paramInt, boolean paramBoolean)
  {
    switch (WifiManager.calculateSignalLevel(paramInt, 4))
    {
    
    case 0:
    	 if (paramBoolean){
           return 2130837510;
         }
         return 2130837505;
    case 1:
    	 if (paramBoolean){
           return 2130837511;
         }
         return 2130837506;
    case 2:
    	 if (paramBoolean){
           return 2130837512;
         }
         return 2130837507;
    case 3:
        if (paramBoolean){
          return 2130837513;
        }
        return 2130837508;
    default:
        if (!paramBoolean){
      	  return 2130837504;
        }
        	return 2130837509;
    }

  }

  private boolean isConnectCamAP()
  {
    boolean bool = false;
    if (this.mWifiManager.isWifiEnabled())
    {
      String str = this.mWifiManager.getConnectionInfo().getSSID();
      if (str != null)
        bool = Utils.supportDSCPrefix(str);
    }
    return bool;
  }

  private void stateWifi()
  {
    switch (this.mWifiManager.getWifiState())
    {
    case 2:
    case 3:
    default:
    case 1:
    }
    while (true)
    {
      this.progressBar.setVisibility(4);
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903045);
    this.mExToast.register(this.mContext, "1", 2130968628, 1);
    this.mExToast.register(this.mContext, "2", 2130968627, 1);
    this.mExToast.register(this.mContext, "3", 2130968624, 1);
    getWindow().addFlags(128);
    this.scanResult = new ArrayList();
    this.accessPointAdapter = new AccessPointAdapter(this.mContext);
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
    localIntentFilter.addAction("android.net.wifi.STATE_CHANGE");
    localIntentFilter.addAction("android.net.wifi.SCAN_RESULTS");
    this.mContext.registerReceiver(this.wifiStateChangedReceiver, localIntentFilter);
    this.mWifiManager = ((WifiManager)this.mContext.getSystemService("wifi"));
    if (!this.mWifiManager.isWifiEnabled())
      this.mWifiManager.setWifiEnabled(true);
    this.btnRefresh = ((Button)findViewById(2131099689));
    this.btnRefresh.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        Logger.d("INRY", "accessPointScan 1");
        WifiDialog.this.accessPointScan();
        WifiDialog.this.accessPointAdapter.notifyDataSetChanged();
      }
    });
    this.btnClose = ((Button)findViewById(2131099690));
    this.btnClose.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        WifiDialog.this.mExToast.unregister(1);
        WifiDialog.this.mExToast.unregister(2);
        WifiDialog.this.mExToast.unregister(3);
        WifiDialog.this.mExToast.hideAll();
        WifiDialog.this.dismiss();
      }
    });
    this.progressBar = ((ProgressBar)findViewById(16842752));
    this.listView = ((ListView)findViewById(2131099687));
    this.wifiConfigurationList = this.mWifiManager.getConfiguredNetworks();
    stateWifi();
    Logger.d("INRY", "accessPointScan 2");
    accessPointScan();
    this.listView.setAdapter(this.accessPointAdapter);
  }

  public class AccessPointAdapter extends BaseAdapter
  {
    private Context mContext;
    private LayoutInflater mInflater;

    public AccessPointAdapter(Context arg2){
      this.mContext = arg2;
      this.mInflater = LayoutInflater.from(this.mContext);
    }

    public int getCount()
    {
      return WifiDialog.this.scanResult.size();
    }

    public Object getItem(int paramInt)
    {
      return Integer.valueOf(paramInt);
    }

    public long getItemId(int paramInt)
    {
      return paramInt;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      Log.d("INRY", "getView Start!!!");
      ScanResult localScanResult = (ScanResult)WifiDialog.this.scanResult.get(paramInt);
      Logger.d("INRY", localScanResult.SSID + "   :" + localScanResult.capabilities);
      String str1 = localScanResult.capabilities;
      String str2 = WifiDialog.this.mWifiManager.getConnectionInfo().getSSID();
      TextView localTextView = (TextView)this.mInflater.inflate(2130903044, null);
      Logger.d("INRY", str1 + "  " + WifiDialog.this.WPSChecker(str1));
      if ((!str1.equals("")) && (!WifiDialog.this.WPSChecker(str1)))
      {
        Logger.d("INRY", str1 + " locked ");
        localTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, WifiDialog.this.getSignalResId(localScanResult.level, true), 0);
      }
      while (true)
      {
        localTextView.setText(localScanResult.SSID);
        Logger.d("INRY", str1);
        localTextView.setTag(localScanResult);
        if ((localScanResult.SSID.equals(str2)) && (WifiDialog.this.isConnected))
        {
          localTextView.setTextColor(-7554461);
          localTextView.setText(Html.fromHtml("<b>" + localScanResult.SSID + "</b>"));
        }
        localTextView.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramView)
          {
            WifiDialog.this.mExToast.show(String.valueOf(2));
            ScanResult localScanResult = (ScanResult)paramView.getTag();
            String str1 = localScanResult.SSID;
            int i = -1;
            Iterator localIterator = WifiDialog.this.wifiConfigurationList.iterator();
            if (!localIterator.hasNext())
            {
              String str2 = WifiDialog.this.mWifiManager.getConnectionInfo().getSSID();
              if ((!localScanResult.SSID.equals(str2)) || (!WifiDialog.this.isConnected))
                break label163;
              Logger.d("INRY", "ALREADY CONNECTED!!");
            }
            while (true)
            {
              return;
              WifiConfiguration localWifiConfiguration1 = (WifiConfiguration)localIterator.next();
              if (!localWifiConfiguration1.SSID.equals("\"" + str1 + "\""))
                break;
              i = localWifiConfiguration1.networkId;
              break;
              label163: Logger.d("INRY", "Capa : " + localScanResult.capabilities + ", networkId=" + i);
              if (i == -1)
              {
                final WifiConfiguration localWifiConfiguration2 = new WifiConfiguration();
                localWifiConfiguration2.SSID = "\"".concat(str1).concat("\"");
                localWifiConfiguration2.status = 1;
                if ((localScanResult.capabilities.equals("")) || (WifiDialog.this.WPSChecker(localScanResult.capabilities)))
                {
                  Logger.d("INRY", "openopenopen!!");
                  localWifiConfiguration2.allowedKeyManagement.set(0);
                  localWifiConfiguration2.allowedProtocols.set(1);
                  localWifiConfiguration2.allowedProtocols.set(0);
                  localWifiConfiguration2.allowedAuthAlgorithms.clear();
                  localWifiConfiguration2.allowedPairwiseCiphers.set(2);
                  localWifiConfiguration2.allowedGroupCiphers.set(0);
                  localWifiConfiguration2.allowedGroupCiphers.set(1);
                  localWifiConfiguration2.allowedGroupCiphers.set(3);
                  localWifiConfiguration2.allowedGroupCiphers.set(2);
                  WifiDialog.this.connect(localWifiConfiguration2);
                  continue;
                }
                if (localScanResult.capabilities.contains("WEP"))
                {
                  Logger.d("INRY", "wepwepwep!!");
                  View localView2 = LayoutInflater.from(WifiDialog.AccessPointAdapter.this.mContext).inflate(2130903040, null);
                  if (WifiDialog.this.mAdialog != null)
                    continue;
                  WifiDialog.this.mAdialog = new AlertDialog.Builder(WifiDialog.AccessPointAdapter.this.mContext);
                  WifiDialog.this.mAdialog.setTitle(2130968622);
                  WifiDialog.this.mAdialog.setView(localView2);
                  WifiDialog.this.mAdialog.setCancelable(false);
                  WifiDialog.this.mAdialog.setPositiveButton(2130968592, new DialogInterface.OnClickListener()
                  {
                    public void onClick(DialogInterface paramDialogInterface, int paramInt)
                    {
                      String str = ((EditText)this.val$textEntryView.findViewById(2131099648)).getText().toString();
                      localWifiConfiguration2.allowedKeyManagement.set(0);
                      localWifiConfiguration2.allowedAuthAlgorithms.set(0);
                      localWifiConfiguration2.allowedAuthAlgorithms.set(1);
                      int i = str.length();
                      if (((i == 10) || (i == 26) || (i == 58)) && (str.matches("[0-9A-Fa-f]*")))
                    	  localWifiConfiguration2.wepKeys[0] = str;
                      while (true)
                      {
                        WifiDialog.this.connect(localWifiConfiguration2);
                        WifiDialog.this.mAdialog = null;
                        return;
                        localWifiConfiguration2.wepKeys[0] = ('"' + str + '"');
                      }
                    }
                  });
                  WifiDialog.this.mAdialog.setNegativeButton(2130968593, new DialogInterface.OnClickListener()
                  {
                    public void onClick(DialogInterface paramDialogInterface, int paramInt)
                    {
                      WifiDialog.this.mAdialog = null;
                    }
                  });
                  AlertDialog localAlertDialog2 = WifiDialog.this.mAdialog.show();
                  WifiDialog.this.mConnectBtn = localAlertDialog2.getButton(-1);
                  WifiDialog.this.mConnectBtn.setEnabled(false);
                  ((EditText)localView2.findViewById(2131099648)).addTextChangedListener(new TextWatcher()
                  {
                    public void afterTextChanged(Editable paramEditable)
                    {
                    }

                    public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
                    {
                    }

                    public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
                    {
                      int i = paramCharSequence.toString().length();
                      if ((1 <= i) && (i <= 26))
                        if (WifiDialog.this.mConnectBtn != null)
                          WifiDialog.this.mConnectBtn.setEnabled(true);
                      while (true)
                      {
                        return;
                        if (WifiDialog.this.mConnectBtn != null)
                        {
                          WifiDialog.this.mConnectBtn.setEnabled(false);
                          continue;
                        }
                      }
                    }
                  });
                  continue;
                }
                Logger.d("INRY", "wpawpawpa!!");
                View localView1 = LayoutInflater.from(WifiDialog.AccessPointAdapter.this.mContext).inflate(2130903040, null);
                if (WifiDialog.this.mAdialog != null)
                  continue;
                WifiDialog.this.mAdialog = new AlertDialog.Builder(WifiDialog.AccessPointAdapter.this.mContext);
                WifiDialog.this.mAdialog.setTitle(2130968622);
                WifiDialog.this.mAdialog.setView(localView1);
                WifiDialog.this.mAdialog.setCancelable(false);
                WifiDialog.this.mAdialog.setPositiveButton(2130968592, new DialogInterface.OnClickListener()
                {
                  public void onClick(DialogInterface paramDialogInterface, int paramInt)
                  {
                	  
                    String str = ((EditText)this.val.textEntryView.findViewById(2131099648)).getText().toString();
                    localWifiConfiguration2.allowedAuthAlgorithms.set(0);
                    localWifiConfiguration2.allowedProtocols.set(1);
                    localWifiConfiguration2.allowedKeyManagement.set(1);
                    localWifiConfiguration2.allowedPairwiseCiphers.set(2);
                    localWifiConfiguration2.allowedPairwiseCiphers.set(1);
                    localWifiConfiguration2.allowedGroupCiphers.set(3);
                    localWifiConfiguration2.allowedGroupCiphers.set(2);
                    localWifiConfiguration2.preSharedKey = "\"".concat(str).concat("\"");
                    WifiDialog.this.connect(localWifiConfiguration2);
                    WifiDialog.this.mAdialog = null;
                  }
                });
               
                WifiDialog.this.mAdialog.setNegativeButton(2130968593, new DialogInterface.OnClickListener()
                {
                  public void onClick(DialogInterface paramDialogInterface, int paramInt)
                  {
                    WifiDialog.this.mAdialog = null;
                  }
                });
                AlertDialog localAlertDialog1 = WifiDialog.this.mAdialog.show();
                WifiDialog.this.mConnectBtn = localAlertDialog1.getButton(-1);
                WifiDialog.this.mConnectBtn.setEnabled(false);
                ((EditText)localView1.findViewById(2131099648)).addTextChangedListener(new TextWatcher()
                {
                  public void afterTextChanged(Editable paramEditable)
                  {
                  }

                  public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
                  {
                  }

                  public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
                  {
                    int i = paramCharSequence.toString().length();
                    if ((8 <= i) && (i <= 63))
                      if (WifiDialog.this.mConnectBtn != null)
                        WifiDialog.this.mConnectBtn.setEnabled(true);
                    while (true)
                    {
                      return;
                      if (WifiDialog.this.mConnectBtn != null)
                      {
                        WifiDialog.this.mConnectBtn.setEnabled(false);
                        continue;
                      }
                    }
                  }
                });
                continue;
              }
              WifiDialog.this.progressBar.setVisibility(0);
              if (WifiDialog.this.mWifiManager.enableNetwork(i, true))
              {
                Logger.d("INRY", "Connected!");
                continue;
              }
              Logger.d("INRY", "Disconnected!");
            }
          }
        });
        return localTextView;
        Logger.d("INRY", str1 + " open ");
        localTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, WifiDialog.this.getSignalResId(localScanResult.level, false), 0);
      }
    }
  }

  private class WifiStateChangedReceiver extends BroadcastReceiver
  {
    private WifiStateChangedReceiver()
    {
    }

    public void onReceive(Context paramContext, Intent paramIntent)
    {
      if (paramIntent.getAction().equals("android.net.wifi.SCAN_RESULTS"))
      {
        WifiDialog.this.progressBar.setVisibility(4);
        return;
      }
      NetworkInfo.DetailedState localDetailedState = null;
      if (paramIntent.getAction().equals("android.net.wifi.STATE_CHANGE"))
        localDetailedState = ((NetworkInfo)paramIntent.getParcelableExtra("networkInfo")).getDetailedState();
      switch (localDetailedState.ordinal())
      {
      case 3:
      default:
        WifiDialog.this.isConnected = false;
        WifiDialog.this.btnClose.setText(2130968617);
        label112: switch (WifiDialog.this.mWifiManager.getWifiState())
        {
        case 0:
        case 2:
        default:
        case 1:
        case 3:
        }
      case 2:
      case 6:
      case 5:
      case 4:
      }
      while (true)
      {
        WifiDialog.this.stateWifi();
        WifiDialog.this.accessPointAdapter.notifyDataSetChanged();
        break;
        if (WifiDialog.this.isConnectCamAP())
        {
          WifiDialog.this.mExToast.show(String.valueOf(1));
          WifiDialog.this.isConnected = true;
          WifiDialog.this.btnClose.setText(2130968616);
          break label112;
        }
        WifiDialog.this.disconnectTheOtherWifi();
        WifiDialog.this.btnClose.setText(2130968617);
        break label112;
        WifiDialog.this.isConnected = false;
        WifiDialog.this.btnClose.setText(2130968617);
        break label112;
        WifiDialog.this.isConnected = false;
        WifiDialog.this.btnClose.setText(2130968617);
        break label112;
        WifiDialog.this.isConnected = false;
        WifiDialog.this.btnClose.setText(2130968617);
        break label112;
        WifiDialog.this.scanResult.clear();
        continue;
        WifiDialog.this.accessPointScan();
      }
    }
  }
}

/* Location:           C:\Users\Chris\Desktop\viewfinder\com.samsung.app-34_dex2jar.jar
 * Qualified Name:     com.samsung.app.WifiDialog
 * JD-Core Version:    0.6.0
 */